package com.studio701.carguard.controller;


import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.pojo.User;
import com.studio701.carguard.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService iUserService;

    @ApiOperation("查找user")
    @GetMapping("/")
    public User getById(Integer id){
        return iUserService.getById(id);
    }

    @ApiOperation("更新user")
    @PutMapping("/")
    RespBean updateAdmin(@RequestBody User user){
        if (iUserService.updateById(user)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.error("更新失败");
        }
    }

    @ApiOperation("删除user")
    @DeleteMapping("/")
    RespBean deleteAdmin(Integer id){
        if (iUserService.removeById(id)){
            return RespBean.success("删除成功");
        }else {
            return RespBean.error("删除失败");
        }
    }
}
